#include <bits/stdc++.h>
using namespace std;
#define int long long

int gcd(int a, int b){
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) {
    return (a * b) / gcd(a, b);
}

void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    int p = n / lcm(a, b);
    int t1 = n / a - p, t2 = n / b - p;
    int x1 = n - t1;
    cout <<  (n * (n + 1)) / 2 - (x1 * (x1 + 1)) / 2 - (t2 * (t2 + 1)) / 2 << endl;
}

signed main() {
    int t; cin >> t;
    while(t--) solve();
    return 0;
}